# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks
_realname=kdeconnect
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=25.04.0
pkgrel=1
pkgdesc="Adds communication between KDE and your smartphone (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: kdeconnect'
  'cpe: cpe:/a:kde:kdeconnect'
)
msys2_repository_url="https://invent.kde.org/network/kdeconnect-kde/"
msys2_documentation_url='https://apps.kde.org/kdeconnect/'
msys2_issue_tracker_url='https://bugs.kde.org/'
url="https://kdeconnect.kde.org/"
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-gcc-libs"
  "${MINGW_PACKAGE_PREFIX}-kcmutils"
  "${MINGW_PACKAGE_PREFIX}-kcolorscheme"
  "${MINGW_PACKAGE_PREFIX}-kconfig"
  "${MINGW_PACKAGE_PREFIX}-kcoreaddons"
  "${MINGW_PACKAGE_PREFIX}-kcrash"
  "${MINGW_PACKAGE_PREFIX}-kdbusaddons"
  "${MINGW_PACKAGE_PREFIX}-kguiaddons"
  "${MINGW_PACKAGE_PREFIX}-ki18n"
  "${MINGW_PACKAGE_PREFIX}-kio"
  "${MINGW_PACKAGE_PREFIX}-kirigami"
  "${MINGW_PACKAGE_PREFIX}-kirigami-addons"
  "${MINGW_PACKAGE_PREFIX}-knotifications"
  "${MINGW_PACKAGE_PREFIX}-kpeople"
  "${MINGW_PACKAGE_PREFIX}-kservice"
  "${MINGW_PACKAGE_PREFIX}-kwidgetsaddons"
  "${MINGW_PACKAGE_PREFIX}-kwindowsystem"
  "${MINGW_PACKAGE_PREFIX}-openssl"
  "${MINGW_PACKAGE_PREFIX}-qqc2-desktop-style"
  "${MINGW_PACKAGE_PREFIX}-qt6-base"
  "${MINGW_PACKAGE_PREFIX}-qt6-connectivity"
  "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
  "${MINGW_PACKAGE_PREFIX}-qt6-multimedia"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-cppwinrt"
  "${MINGW_PACKAGE_PREFIX}-extra-cmake-modules"
  "${MINGW_PACKAGE_PREFIX}-gettext-tools"
  "${MINGW_PACKAGE_PREFIX}-icoutils"
  "${MINGW_PACKAGE_PREFIX}-kdoctools"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-qt6-declarative"
  "${MINGW_PACKAGE_PREFIX}-qt6-tools"
)
groups=(
  "${MINGW_PACKAGE_PREFIX}-kde-applications"
  "${MINGW_PACKAGE_PREFIX}-kde-network"
)
source=("https://download.kde.org/stable/release-service/${pkgver}/src/${_realname}-kde-${pkgver}.tar.xz"{,.sig}
        "0001-kdeconnect-workaround-missing-in4addr_any.patch"
        "0002-kdeconnect-cmake-add-fexceptions.patch"
        "0003-kdeconnect-remove-in-sal.patch"
        "0004-kdeconnect-cmake-disable-checking-winsdk.patch")
sha256sums=('144a65ed741dd37bec4e30703c939f49b8becdb51075bd5702d7adede91d5ca8'
            'SKIP'
            'd026cc43404dfdfe6060cad2818f57fcdf00c1f5ab683762a0f07de0c771f51d'
            'e8a0a39da7da94893b100a384cb8738f13470291c14dfae9ccf68835ac4cec55'
            '35b447bef8eec27e601d43c58af8cd0ebd92534b92e76faf369936fed0db0d26'
            '38c72e5e6219fc6ca25efb5daf2618404d01e24210d4129460baaf9b3d39fcae')
validpgpkeys=(CA262C6C83DE4D2FB28A332A3A6A4DB839EAA6D7  # Albert Astals Cid <aacid@kde.org>
              F23275E4BF10AFC1DF6914A6DBD2CE893E2D1C87  # Christoph Feck <cfeck@kde.org>
              D81C0CB38EB725EF6691C385BB463350D6EF31EF) # Heiko Becker <heiko.becker@kde.org>

_apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -p1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd "${_realname}-kde-${pkgver}"

  _apply_patch_with_msg \
    0001-kdeconnect-workaround-missing-in4addr_any.patch \
    0002-kdeconnect-cmake-add-fexceptions.patch \
    0003-kdeconnect-remove-in-sal.patch \
    0004-kdeconnect-cmake-disable-checking-winsdk.patch
}

build() {
  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  _kde_build_env
  CXXFLAGS+=" -Wno-c++11-narrowing" \
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    "${MINGW_PREFIX}"/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${_KDE_INSTALL_DIRS[@]}" \
      -DBUILD_TESTING=OFF \
      "${_extra_config[@]}" \
      -S "${_realname}-kde-${pkgver}" \
      -B "build-${MSYSTEM}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}"
}
